/*
* 根据省份id获取该省份中的城市
* data 数据格式
* {
*"city":[{
 "name":"北京",
 "url":"http://www.baidu.com"
 },{
 "name":"上海",
 "url":"http://www.baidu.com"
 },{
 "name":"天津",
 "url":"http://www.baidu.com"
 },{
 "name":"山东",
 "url":"http://www.baidu.com"
 }]
* }
* */
define(function(require,exports,module){
    var url = require('mod-url');
    var $ = require("$");
    function getCity(provId,cityWrapId,provName){
        var $cityBox = $("#"+cityWrapId).find('dl');
        $.getJSON(lemon.site_url+"ajax.php?"+"module=common&action=wzchaxun",{ 'provid':provId },function(data){
            if(data.city.length>0){
                var $title = $("<dt>"+provName+"</dt>");
                $cityBox.empty();
                $cityBox.append($title);
                for (var p in data.city){
                    var $city = $("<dd><a href='"+ data.city[p].url+"' target='_blank'>"+ data.city[p].areaname+"</a> </dd>");
                    $cityBox.append($city);
                }
                $("#"+cityWrapId).show();
            }
        });
    }
    exports.showCity = function(mapWrapId,cityWrapId){
        var $map =  $("#"+mapWrapId),$cityBox = $("#"+cityWrapId);
        var currentCity = $('#area-field').attr('data-map');
        $map.find('area').each(function(){
            $(this).hover(function(e){
                var provId = parseInt($(this).attr('cid').substring(4)),
                    provName = $(this).attr('dtitle'),
                    top = e.clientY+$(window).scrollTop(),
                    left = e.clientX+$(window).scrollLeft();
                $cityBox.css({
                    "top":top,
                    "left":left
                });
                getCity(provId,cityWrapId,provName);
            },function(){
                $cityBox.hide()
            });
        });
        $cityBox.hover(function(event){
            event.stopPropagation();
            $(this).show();
        },function(){
            $(this).hide();
        });
    }
});